package com.jf3q.sup.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jf3q.sup.domain.Products;
import com.jf3q.sup.dto.ProductsDto;
import com.jf3q.sup.vo.ProductsVo;
import com.jf3q.sup.service.ProductsService;
import com.jf3q.sup.mapper.ProductsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import com.jf3q.sup.vo.products.ProductsAndEchartsMonth;
import com.jf3q.sup.vo.products.ProductsEchartsVo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 *
 */
@Service
public class ProductsServiceImpl extends ServiceImpl<ProductsMapper, Products>
    implements ProductsService{
    @Autowired
    private ProductsMapper productsMapper;



    @Override
    public Page<ProductsVo> ClassificationAndDetails(ProductsDto productsDto) {
        Page<ProductsVo> page = new Page<>(productsDto.getPageNum(), productsDto.getPageSize());
        Page<ProductsVo> pages = productsMapper.ClassificationAndDetails(page,productsDto);
        return pages;
    }


    @Override
    public ProductsEchartsVo getEcharts() {
        int echartsCount = productsMapper.getEchartsCount();
        List<ProductsAndEchartsMonth> echartsMonthList = productsMapper.getEcharts();

        ProductsEchartsVo.Title title = new ProductsEchartsVo.Title("商品总数量:" + echartsCount);
        List<String> monthList = new ArrayList<>();
        List<Integer> countProductsList = new ArrayList<>();
        for (ProductsAndEchartsMonth productsAndEchartsMonth : echartsMonthList) {
            monthList.add(productsAndEchartsMonth.getMonth());
            countProductsList.add(productsAndEchartsMonth.getProductCount());
        }
        ProductsEchartsVo.XAxis xAxis = new ProductsEchartsVo.XAxis(monthList);
        ProductsEchartsVo.Series series = new ProductsEchartsVo.Series("bar", countProductsList);
        ProductsEchartsVo productsEchartsVo = new ProductsEchartsVo(title, xAxis, List.of(series));

        return productsEchartsVo;
    }

    @Override
    public List<Products> getList(Integer sId) {
        LambdaQueryWrapper<Products> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Products::getSuppliersId,sId);
        return productsMapper.selectList(lambdaQueryWrapper);
    }
}




